package cn.keniykey.mc.landterritory.config;

import java.io.File;

import org.bukkit.configuration.file.YamlConfiguration;

import cn.keniykey.mc.landterritory.LandTerritoryMain;

public final class WorldsConfiguration {
	private static final String FILE_NAME = "worlds.yml";
	private static YamlConfiguration yaml;
	
	private static YamlConfiguration getWorldYamlForDir() {
		final LandTerritoryMain main = LandTerritoryMain.getPlugin();
		final File dirfile = main.getDataFolder();
		dirfile.mkdirs();
		final File langfile = new File(dirfile, FILE_NAME);
		if(!langfile.exists()) {
			if(main.getResource(FILE_NAME) != null) {
				main.saveResource(FILE_NAME, true);
			}else {
				main.getLogger().warning(FILE_NAME + " null");
				return new YamlConfiguration();
			}
		}
		return YamlConfiguration.loadConfiguration(langfile);
	}
	public static void reloadWorldsConfiguration() {
		yaml = getWorldYamlForDir();
	}
	public static String getWorldName(String worldname) {
		return yaml.getString(worldname, worldname);
	}
}